﻿#include "Message.h"

int8 Bean::readInt8(ByteBuf& buf){
	return buf.readInt8();
}

void Bean::writeInt8(ByteBuf& buf, int8 value){
	buf.writeInt8(value);
}

short Bean::readShort(ByteBuf& buf){
	return readInt16(buf);
}

void Bean::writeShort(ByteBuf& buf, short value){
	buf.writeInt16(value);
}

int16 Bean::readInt16(ByteBuf& buf){
	return buf.readInt16();
}

void Bean::writeInt16(ByteBuf& buf, int16 value){
	buf.writeInt16(value);
}

int32 Bean::readInt32(ByteBuf& buf){
	return buf.readInt32();
}

void Bean::writeInt32(ByteBuf& buf, int32 value){
	buf.writeInt32(value);
}

int64 Bean::readInt64(ByteBuf& buf){
	return buf.readInt64();
}

void Bean::writeInt64(ByteBuf& buf, int64 value){
	buf.writeInt64(value);
}

std::string& Bean::readString(ByteBuf& buf, std::string& value){
	int32 len = readInt32(buf);
	if (len <= 0 || len > buf.readableSize()){
		return value;
	}
	value = std::string((char*)buf.readDatas(len), len);
	return value;
}

void Bean::writeString(ByteBuf& buf, std::string& value){
	if (value.size() <= 0){
		writeInt32(buf, 0);
		return;
	}
	writeInt32(buf, value.size());
	buf.writeDatas(value.c_str(), value.size());
}

Bean& Bean::readBean(ByteBuf& buf, Bean& value){
	value.read_from(buf);
	return value;
}

void Bean::writeBean(ByteBuf& buf, Bean& value){
	value.write_to(buf);
}




Message::Message(){
}

Message::~Message(){
	//log("release message %d",(int)this);
}

void Message::reset(){
}
